package com.lx.designPattern.factory;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2022-02-24 11:27:44
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2022-02-24     张李鑫                     1.0         1.0 Version
 */
public class BeanFactory {
    static abstract class Person {
        public abstract void sleep();

        public abstract void eat();

        public abstract void run();
    }


    public static class Teacher extends Person {

        @Override
        public void sleep() {
            System.out.println("teacher sleep");
        }

        @Override
        public void eat() {
            System.out.println("teacher eat");
        }

        @Override
        public void run() {
            System.out.println("teacher run");
        }
    }

    public static class Student extends Person {
        @Override
        public void sleep() {
            System.out.println("Student sleep");
        }

        @Override
        public void eat() {
            System.out.println("Student eat");
        }

        @Override
        public void run() {
            System.out.println("Student run");
        }
    }


    public Person createBean(Class tClass) {
        try {
            return (Person) tClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        BeanFactory beanFactory = new BeanFactory();
        Person student = beanFactory.createBean(Student.class);
        Person teacher = beanFactory.createBean(Teacher.class);
        student.eat();
        student.run();
        student.sleep();

        System.out.println();

        teacher.eat();
        teacher.run();
        teacher.sleep();
    }

}
